<?php

namespace Frieza\Modules\Totem\Actions;

use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
use Doraemon\model\Totem\Totems;

class SoldOutTotem extends RowAction
{
    public $name = '下架徽章';
    const TOAST_ALERT = '是否要下架此徽章,下架后未获得该徽章的用户将进入徽章博物馆,无法获得该徽章?';

    public function handle($id)
    {
       $data['totem_status'] = Totems::STATUS_DELETE;
       $result = Totems::updateData($data, ['id' => $id]);
        if ($result) {
            return $this->response()->success('下架该徽章成功!')->refresh();
        }else{
            return $this->response()->error('下架失败,请稍后重试!!');
        }
    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function dialog()
    {
        $this->confirm(self::TOAST_ALERT);
    }
}
